import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(ElementUI);
Vue.use(VueAxios, axios)
Vue.config.productionTip = false



// Vue.prototype.$baseUrl = 'http://localhost:81/';
Vue.prototype.$baseUrl = 'http://api.com/';



axios.interceptors.request.use(config=>{
  // debugger
  console.log(config);
  let userinfo = localStorage.getItem("userinfo") || '{}';
  console.log("v"+userinfo);
  let userinfostr = JSON.parse(userinfo);
  // @ts-ignore
  config.headers['token'] = userinfostr.token;
  console.log("token",userinfostr.token)
  console.log("path:",window.location.href)
  if (userinfostr.token==undefined && window.location.href!='http://www.bw.com/Login') {
    router.push("/Login");
  }
  return config;
},err=>{
  router.push("/Login")
  return Promise.reject(err);
})

//http response 拦截器
axios.interceptors.response.use(response=>{
  console.log("response",response)
  console.log("requestUrl:"+response.config.url);
  console.log("responseData",response.data.data);
  return response;
},err=>{
  console.log(err);
  router.push("/Login")
  return Promise.reject(err.response.status);
});


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
